﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Data.SqlClient;
//using SQLDMO;
using Microsoft.Win32;

namespace BHair
{
    public partial class frmbak : Form
    {
        public frmbak()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            saveFileDialog1.ShowDialog();

            this.txtlj.Text = saveFileDialog1.FileName.ToString();
        }

        private void button2_Click(object sender, EventArgs e)
        {
           
            bak();
        }
        public void bak() 
        {
            this.txtlj.Text = saveFileDialog1.FileName.ToString();
            string lj = this.txtlj.Text;
            string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
            SqlConnection conn1 = new SqlConnection(constr);
           // MessageBox.Show(lj);
            string sql1 =string.Format( "use master;backup database BHairDB to disk='{0}'",lj);
            try
            {
                conn1.Open();
                SqlCommand comm1 = new SqlCommand(sql1,conn1);
                comm1.ExecuteNonQuery();
                MessageBox.Show("备份成功文件保存："+"\t"+lj);
                conn1.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                conn1.Close();
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
            
        }

        private void frmbak_Load(object sender, EventArgs e)
        {

        }
    }
}
